VERSION 5.00
Begin VB.Form DLGpreferences 
   BackColor       =   &H00E0E0E0&
   BorderStyle     =   3  'Fixed Dialog
   Caption         =   "Preferences"
   ClientHeight    =   7500
   ClientLeft      =   2760
   ClientTop       =   3750
   ClientWidth     =   6855
   BeginProperty Font 
      Name            =   "Verdana"
      Size            =   8.25
      Charset         =   0
      Weight          =   400
      Underline       =   0   'False
      Italic          =   0   'False
      Strikethrough   =   0   'False
   EndProperty
   Icon            =   "DLGpreferences.frx":0000
   LinkTopic       =   "Form1"
   MaxButton       =   0   'False
   MinButton       =   0   'False
   ScaleHeight     =   500
   ScaleMode       =   3  'Pixel
   ScaleWidth      =   457
   ShowInTaskbar   =   0   'False
   StartUpPosition =   1  'CenterOwner
   Begin VB.Frame Frame2 
      BackColor       =   &H00E0E0E0&
      Caption         =   "Default Export Fields"
      BeginProperty Font 
         Name            =   "Verdana"
         Size            =   8.25
         Charset         =   0
         Weight          =   700
         Underline       =   0   'False
         Italic          =   0   'False
         Strikethrough   =   0   'False
      EndProperty
      Height          =   1815
      Left            =   240
      TabIndex        =   16
      Top             =   2400
      Width           =   6375
      Begin VB.ListBox LISTdefaultExportFields 
         Height          =   1230
         ItemData        =   "DLGpreferences.frx":0442
         Left            =   2160
         List            =   "DLGpreferences.frx":0444
         MultiSelect     =   2  'Extended
         TabIndex        =   17
         Top             =   360
         Width           =   3975
      End
      Begin VB.Label Label6 
         BackStyle       =   0  'Transparent
         Caption         =   "Fields to export"
         Height          =   255
         Left            =   240
         TabIndex        =   18
         Top             =   360
         Width           =   1935
      End
   End
   Begin VB.Frame Frame1 
      BackColor       =   &H00E0E0E0&
      Caption         =   "Default DataBase"
      BeginProperty Font 
         Name            =   "Verdana"
         Size            =   8.25
         Charset         =   0
         Weight          =   700
         Underline       =   0   'False
         Italic          =   0   'False
         Strikethrough   =   0   'False
      EndProperty
      Height          =   1335
      Left            =   240
      TabIndex        =   8
      Top             =   840
      Width           =   6375
      Begin VB.TextBox TXTdefaultDatabasePath 
         Height          =   285
         Left            =   240
         TabIndex        =   19
         Top             =   360
         Width           =   4575
      End
      Begin VB.ComboBox LISTfields 
         Height          =   315
         Left            =   2160
         Style           =   2  'Dropdown List
         TabIndex        =   11
         Top             =   800
         Width           =   3975
      End
      Begin VB.CommandButton BTNbrowse 
         Caption         =   "Browse"
         Height          =   300
         Left            =   5040
         TabIndex        =   9
         Top             =   350
         Width           =   1095
      End
      Begin VB.Label Label1 
         BackStyle       =   0  'Transparent
         Caption         =   "Default Search Field"
         Height          =   255
         Left            =   240
         TabIndex        =   10
         Top             =   870
         Width           =   1935
      End
   End
   Begin VB.Frame Frame4 
      BackColor       =   &H00E0E0E0&
      Caption         =   "Remote DataBase"
      BeginProperty Font 
         Name            =   "Verdana"
         Size            =   8.25
         Charset         =   0
         Weight          =   700
         Underline       =   0   'False
         Italic          =   0   'False
         Strikethrough   =   0   'False
      EndProperty
      Height          =   2295
      Left            =   240
      TabIndex        =   3
      Top             =   4440
      Width           =   6375
      Begin VB.TextBox TXTdatabaseName 
         Height          =   285
         Left            =   1920
         TabIndex        =   14
         Text            =   "DATABASE_NAME.mdb"
         Top             =   1050
         Width           =   4215
      End
      Begin VB.TextBox TXTfieldNames 
         Height          =   285
         Left            =   240
         TabIndex        =   13
         Text            =   "NAME_1,NAME_2,NAME_3"
         Top             =   1800
         Width           =   5895
      End
      Begin VB.TextBox TXTupdatePagePath 
         Height          =   285
         Left            =   1920
         TabIndex        =   7
         Text            =   "FOLDER(s)/PAGE_NAME"
         Top             =   675
         Width           =   4215
      End
      Begin VB.TextBox TXTserverAddress 
         Height          =   285
         Left            =   1920
         TabIndex        =   6
         Text            =   "http://SERVER_NAME"
         Top             =   285
         Width           =   4215
      End
      Begin VB.Label Label5 
         BackStyle       =   0  'Transparent
         Caption         =   "Database Name"
         Height          =   255
         Left            =   240
         TabIndex        =   15
         Top             =   1125
         Width           =   1695
      End
      Begin VB.Label Label4 
         BackStyle       =   0  'Transparent
         Caption         =   "Field Names (seperated by commas)"
         Height          =   255
         Left            =   240
         TabIndex        =   12
         Top             =   1515
         Width           =   4815
      End
      Begin VB.Label Label3 
         BackStyle       =   0  'Transparent
         Caption         =   "Update Page Path"
         Height          =   255
         Left            =   240
         TabIndex        =   5
         Top             =   750
         Width           =   1695
      End
      Begin VB.Label Label2 
         BackStyle       =   0  'Transparent
         Caption         =   "Server Address"
         Height          =   255
         Left            =   240
         TabIndex        =   4
         Top             =   360
         Width           =   1575
      End
   End
   Begin VB.CommandButton CMDcancel 
      BackColor       =   &H00E0E0E0&
      Caption         =   "Cancel"
      Default         =   -1  'True
      Height          =   375
      Left            =   5490
      TabIndex        =   2
      Top             =   6960
      Width           =   1095
   End
   Begin VB.CommandButton CMDsaveColumnWidths 
      Caption         =   "Save Column Widths"
      Height          =   375
      Left            =   4440
      TabIndex        =   1
      ToolTipText     =   "Saves column widths According to their current width"
      Top             =   240
      Width           =   2175
   End
   Begin VB.CommandButton CMDok 
      Caption         =   "OK"
      Height          =   375
      Left            =   4290
      TabIndex        =   0
      Top             =   6960
      Width           =   1095
   End
End
Attribute VB_Name = "DLGpreferences"
Attribute VB_GlobalNameSpace = False
Attribute VB_Creatable = False
Attribute VB_PredeclaredId = True
Attribute VB_Exposed = False


' Form load event ---------------------------------------------------------------------------------------------------------------------------

Public Sub Form_Load()

    On Error Resume Next
    
    Dim aSplitDefaultExportFields As Variant

    Dim sDefaultExportFieldsList As String

    With New regOp
    
        .Root = HKEY_LOCAL_MACHINE
        
        .Key = "Software\bbd\AccessSearch\preferences"
        
        Me.TXTdefaultDatabasePath.Text = .Value("defaultDatabasePath")
        defaultSearchField = .Value("defaultSearchField")
        
        sDefaultExportFieldsList = .Value("defaultExportFields")
        
        .Key = "Software\bbd\AccessSearch\preferences\remoteDB"
        
        Me.TXTserverAddress.Text = .Value("serverAddress")
        Me.TXTupdatePagePath.Text = .Value("updatePagePath")
        Me.TXTfieldNames.Text = .Value("fieldNames")
        Me.TXTdatabaseName.Text = .Value("databaseName")
        
    End With
    
    Me.TXTdefaultDatabasePath.ToolTipText = Me.TXTdefaultDatabasePath.Text
    
    buildDefaultFieldFieldsList
    
    For i = 0 To Me.LISTfields.ListCount - 1
    
        If defaultSearchField = Me.LISTfields.List(i) Then
        
            Me.LISTfields.ListIndex = i
            
            Exit For
            
        End If
        
    Next
    
    aSplitDefaultExportFields = Split(sDefaultExportFieldsList, ",")
    
    For i = 0 To Me.LISTdefaultExportFields.ListCount
    
        For j = 0 To UBound(aSplitDefaultExportFields)
        
            If aSplitDefaultExportFields(j) = LISTdefaultExportFields.List(i) Then
            
                LISTdefaultExportFields.Selected(i) = True
                
                Exit For
            
            End If
        
        Next
        
    Next
    
End Sub



Private Sub Form_KeyUp(KeyCode As Integer, Shift As Integer)

    On Error Resume Next

    If KeyCode = 27 Then
    
        Unload Me
        
    End If
    
End Sub


Private Sub buildDefaultFieldFieldsList()

    On Error Resume Next
    
    LISTfields.Clear
    
    For i = 0 To FRMmain.LISTfields.ListCount - 1
    
        Me.LISTfields.AddItem (FRMmain.LISTfields.List(i))
        Me.LISTdefaultExportFields.AddItem FRMmain.LISTfields.List(i)
        
    Next
    
End Sub

Private Function validDefaultSearchField() As Boolean

    On Error Resume Next

    Dim sDefaultSearchField As String

    If Not IsNumeric(Me.LISTfields.ListIndex) Or Me.LISTfields.ListIndex < 0 Then
    
        Exit Function
        
    End If
    
    sDefaultSearchField = LISTfields.List(LISTfields.ListIndex)
    
    For i = 0 To FRMmain.LISTfields.ListCount - 1
    
        If sDefaultSearchField = FRMmain.LISTfields.List(i) Then
        
            validDefaultSearchField = True
            
            Exit Function
            
        End If
        
    Next
    
End Function

' Events -------------------------------------------------------------------------------------------------------------------------

' OK button click event -----------------------------------------------------------------------------------------------------------------------------------------

Private Sub CMDok_Click()

    On Error Resume Next

    Dim _
        sDefaultSearchField As String, _
        sDefaultExportFieldsList As String
        
    Dim iConfirm

    If Not validDefaultSearchField Then
    
        iConfirm = MsgBox("You have chosen an invalid default search field", vbOKCancel)
        
        If iConfirm <> 1 Then Exit Sub
        
    End If

    With New regOp
    
        .Root = HKEY_LOCAL_MACHINE
        .Key = "Software\bbd\AccessSearch\preferences"
        .Value("defaultDatabasePath") = Me.TXTdefaultDatabasePath.Text
         
        If IsNumeric(Me.LISTfields.ListIndex) And Me.LISTfields.ListIndex >= 0 Then
            
            sDefaultSearchField = LISTfields.List(Me.LISTfields.ListIndex)
        
            If sDefaultSearchField = "" Then sDefaultSearchField = "All"
        
            If validDefaultSearchField Then .Value("defaultSearchField") = sDefaultSearchField
            
            For i = 0 To FRMmain.LISTfields.ListCount - 1
                
                If sDefaultSearchField = FRMmain.LISTfields.List(i) Then
                
                    FRMmain.LISTfields.ListIndex = i
                    
                    Exit For
                    
                End If
                
            Next
    
        End If
        
        For i = 0 To LISTdefaultExportFields.ListCount - 1
        
            If LISTdefaultExportFields.Selected(i) = True Then
            
                sDefaultExportFieldsList = sDefaultExportFieldsList & LISTdefaultExportFields.List(i) & ","
            
            End If
        
        Next
        
        If Len(sDefaultExportFieldsList) > 0 Then
        
            sDefaultExportFieldsList = Left(sDefaultExportFieldsList, Len(sDefaultExportFieldsList) - 1)
        
            .Value("defaultExportFields") = sDefaultExportFieldsList
            
        End If
          
        .Key = "Software\bbd\AccessSearch\preferences\remoteDB"
        .Value("serverAddress") = Me.TXTserverAddress.Text
        .Value("updatePagePath") = Me.TXTupdatePagePath.Text
        .Value("fieldNames") = Me.TXTfieldNames.Text
        .Value("databaseName") = Me.TXTdatabaseName.Text
        
    End With

    
    Unload Me
    
End Sub

' Save the current column widths -------------------------------------------------------------------------------------------------------

Private Sub CMDsaveColumnWidths_Click()

    MODpreferences.saveColumnWidths

End Sub

' Browse for choosing the default database -----------------------------------------------------------------------

Private Sub BTNbrowse_Click()

    On Error GoTo errorHandler
    
    FRMmain.CommonDialog.ShowOpen
    
    With FRMmain.CommonDialog
    
        If .FileName <> "" Then
        
            TXTdefaultDatabasePath.Text = .FileName
            TXTdefaultDatabasePath.ToolTipText = .FileName
            
        End If
        
    End With
    
    buildDefaultFieldFieldsList
    
errorHandler:

    If Err.Number <> 0 Then
    
        MsgBox Err.Description & vbCrLf & Err.Number
        
    End If
    
End Sub

' Cancel ----------------------------------------------------------------------------------------------

Private Sub CMDcancel_Click()

    Unload Me

End Sub

Private Sub LISTdefaultExportFields_Click()

    On Error Resume Next

    ' If 'All' is clicked, then select all of the listItems ----------------------------------------------------------------

    If LISTdefaultExportFields.Selected(0) = True Then
    
        For i = 1 To LISTdefaultExportFields.ListCount - 1
             
            LISTdefaultExportFields.Selected(i) = True
        
        Next
    
    End If

End Sub



